﻿using System;
using DBAccessLibrary.Model;
using DBAccessLibrary;
using System.Windows;

namespace QueryResource.ViewModel
{
    public class RegistDBViewModel
    {
        public RegistDBViewModel()
        {
            DataSource = new ConnectionModel {ConnectType = DBType.DB2};
        }

        public ConnectionModel DataSource { get; set; }

        public bool Connection(bool isTest=false)
        {
            try
            {
                if (isTest)
                {
                    string error = DBOperatorFactory.GetOperator.IsConnectDB(DataSource);
                    if (error == string.Empty)
                        return true;

                    MessageBox.Show(error);
                    return false;
                }
                DBOperatorFactory.GetOperator.ConnectDB(DataSource);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
        
    }
}
